home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5305 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.1 KB  |  68 lines

  1. Path: ix.netcom.com!netnews
  2. From: wzjn@ix.netcom.com (KPN )
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help for a float problem
  5. Date: 9 Feb 1996 20:47:24 GMT
  6. Organization: Netcom
  7. Message-ID: <4fgbss$nqm@ixnews6.ix.netcom.com>
  8. References: <AMCHAVAN.96Jan25112007@ac2.hq.eso.org> <4f6tt6$rt1@news.cencom.net> <311A83D1.57A3@feith.com> <4fe4m4$f1c@news.ee.net> <4fflin$92t@murrow.corp.sgi.com> <4fgal6$fm8@lois.Read.TASC.COM> <4fgbdc$92t@murrow.corp.sgi.com>
  9. NNTP-Posting-Host: ix-frm-ma2-04.ix.netcom.com
  10. X-NETCOM-Date: Fri Feb 09 12:47:25 PM PST 1996
  11.  
  12. Good Afternoon,
  13.  
  14. Using æHow To Program C (second edition)Æ by Deitel & Deitel, IÆm
  15. trying to do on page 92, example 3.17. IÆm not sure, but believe that
  16. my problem is where to use a æfloatÆ. 
  17.  
  18. I want to ask the user to enter gallons used, which of course, could be
  19. 12.8. However, with the same line, I want the user to enter æ-1Æ if
  20. they choose to end the program.
  21.  
  22. The way it is written so far, the user can successfully exit the
  23. program with a -1. The user can also successfully enter whole numbers
  24. and get an answer. My problem arises when I enter (again) 12.8 ... the
  25. program goes in to an infinate loop! eh?
  26.  
  27. Conversely, if I define gallons as a float, the program does not
  28. recognize the æ-1Æ as an end of program. eh? 
  29.  
  30. Someone have the time to tell me where my problem lies? IÆm not in a
  31. class, this is only for my benefit, but I would like to know what to do
  32. here / what the æwork-aroundÆ is. Here is my code:
  33.  
  34. #include <stdio.h>
  35.  
  36. main()
  37. {
  38.    int miles, answer, gallons;
  39.  
  40.    printf("Enter the gallons used (-1 to end): \n");
  41.    scanf("%d", &gallons);
  42.  
  43.    while (gallons != -1)
  44.    {
  45.       printf("Enter the miles driven:\n");
  46.       scanf("%d", &miles);
  47.  
  48.       answer = miles / gallons;
  49.       printf("The miles / gallons for this tank was %d\n", answer);
  50.  
  51.       printf("Enter the gallons used (-1 to end): \n");
  52.       scanf("%d", &gallons);
  53.  
  54.       /* printf("Enter the miles driven:\n");
  55.       scanf("%d", &miles); */
  56.    }
  57. return 0;
  58. }
  59.  
  60.  
  61. Thank you for your help,
  62.  
  63. kevin
  64.  
  65. ôWhen their numbers dwindled from 50 down to 8, the remaining dwarfs
  66. began to suspect æHungryÆ.ö
  67.  
  68.